<template>
  <!-- 钥匙到期状态 -->
  <el-card class="box-card" style="height: 320px;">
    <div slot="header" class="clearfix">
      <svg-icon icon-class="钥匙" style="font-size: 20px;"></svg-icon>
      <span class="title">钥匙到期状态</span>
    </div>
    <div class="key-expiry-container">
      <div class="key-expiry-cards">
        <!-- 已到期卡片 -->
        <div class="key-expiry-card expired" @click="navigateToKeys('expired')">
          <div class="card-icon">
            <i class="el-icon-time"></i>
          </div>
          <div class="card-content">
            <div class="card-count">{{ expiredCount }}</div>
            <div class="card-title">已到期</div>
          </div>
        </div>
        
        <!-- 即将到期卡片 -->
        <div class="key-expiry-card expiring" @click="navigateToKeys('expiring')">
          <div class="card-icon">
            <i class="el-icon-warning-outline"></i>
          </div>
          <div class="card-content">
            <div class="card-count">{{ expiringCount }}</div>
            <div class="card-title">即将到期</div>
            <div class="card-subtitle">3天内</div>
          </div>
        </div>
        
        <!-- 有效期内卡片 -->
        <div class="key-expiry-card valid" @click="navigateToKeys('valid')">
          <div class="card-icon">
            <i class="el-icon-success"></i>
          </div>
          <div class="card-content">
            <div class="card-count">{{ validCount }}</div>
            <div class="card-title">有效期内</div>
          </div>
        </div>
      </div>
      
      <div class="key-expiry-total">
        <div class="total-label">钥匙总数</div>
        <div class="total-count">{{ totalCount }}</div>
      </div>
    </div>
  </el-card>
</template>

<script>
  import * as echarts from "echarts";
  import {
    keyExpiryStatus
  } from "@/api/lock/menu";
  export default {
    data() {
      return {
        expiredCount: 0,
        expiringCount: 0,
        validCount: 0,
        totalCount: 0
      }
    },
    created() {
      this.getKeyExpiryStatusCount();
    },
    methods: {
      getKeyExpiryStatusCount() {
        keyExpiryStatus().then(response => {
          console.log("钥匙到期状态统计:", response.data);
          this.expiredCount = response.data.expiredCount || 0;
          this.expiringCount = response.data.expiringCount || 0;
          this.validCount = response.data.validCount || 0;
          this.totalCount = this.expiredCount + this.expiringCount + this.validCount;
        });
      },
      
      // 跳转到钥匙管理界面并应用过滤条件
      navigateToKeys(expiryStatus) {
        this.$router.push({
          path: '/tenantkey',
          query: {
            expiryStatus: expiryStatus
          }
        });
      }
    }
  }
</script>

<style lang="scss" scoped>
.key-expiry-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 10px 0;
}

.key-expiry-cards {
  display: flex;
  justify-content: space-between;
  margin-bottom: 20px;
  flex: 1;
}

.key-expiry-card {
  flex: 1;
  display: flex;
  align-items: center;
  padding: 15px;
  border-radius: 8px;
  margin: 0 10px;
  color: white;
  transition: all 0.3s;
  cursor: pointer;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  
  &:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 15px 0 rgba(0, 0, 0, 0.15);
  }
  
  &.expired {
    background: linear-gradient(135deg, #F56C6C 0%, #F78989 100%);
  }
  
  &.expiring {
    background: linear-gradient(135deg, #E6A23C 0%, #EEBE77 100%);
  }
  
  &.valid {
    background: linear-gradient(135deg, #67C23A 0%, #85CE61 100%);
  }
}

.card-icon {
  font-size: 36px;
  margin-right: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.2);
}

.card-content {
  flex: 1;
}

.card-count {
  font-size: 28px;
  font-weight: bold;
  line-height: 1.2;
}

.card-title {
  font-size: 16px;
  margin-top: 5px;
}

.card-subtitle {
  font-size: 12px;
  opacity: 0.8;
}

.key-expiry-total {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px 20px;
  background-color: #f5f7fa;
  border-radius: 8px;
  margin: 0 10px;
}

.total-label {
  font-size: 16px;
  color: #606266;
  margin-right: 15px;
}

.total-count {
  font-size: 24px;
  font-weight: bold;
  color: #303133;
}
</style>
